package com.jp.knowledge.my.fragment;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;

import com.jp.knowledge.activity.KnowlageDetailActivity;
import com.jp.knowledge.broad.LocalBroadCast;
import com.jp.knowledge.fragment.CollectionNewsFragment;
import com.jp.knowledge.model.ProductUIModel;
import com.jp.knowledge.my.adapter.CollectionAlbumAdapter;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.model.CollectionAlbumModel;
import com.jp.knowledge.view.JpDiver;

import java.util.List;

public class CollectionAlbumFragment extends CollectionNewsFragment {

	@Override
	protected RecyclerView.Adapter initAdapter(List datas) {
		contentRv.addItemDecoration(new JpDiver(mContext));
		final CollectionAlbumAdapter adapter = new CollectionAlbumAdapter(mContext, datas);
		adapter.addItemClickListener(new RecycleVAdapter.OnItemClickListener() {
			@Override
			public void itemSelect(int position) {
				Intent intent = new Intent(mContext, KnowlageDetailActivity.class);
				intent.putExtra("packageId", adapter.getData(position).getPackageId());
				intent.putExtra("title", adapter.getData(position).getPackageTitle());
				startActivity(intent);
			}
		});
		adapter.setItemCloseClickListner(new CollectionAlbumAdapter.ItemCloseClickListner() {
			@Override
			public void onItemCloseClick(int position) {
				onItemDelete(adapter.getData(position).getPackageId(), 26, position*10+DELETE_ITEM_CODE);
			}
		});
		return adapter;
	}

	@Override
	protected Class getDatasType() {
		return CollectionAlbumModel.class;
	}

	@Override
	protected void onBroadCastReceive(String action, Intent intent){
		if(LocalBroadCast.COMM_CHANGE_SIZE.equals(action))
			((CollectionAlbumAdapter)adapter).changeTextSize();
		else
			super.onBroadCastReceive(action, intent);
	}

	protected boolean isSameItem(Object data, String id){
		return (id != null && data != null && id.equals(((CollectionAlbumModel)data).getPackageId()));
	}
}
